package com.appium.manager.element.config.ymlHandler;

import com.appium.manager.util.YamlUtil;

import java.io.FileNotFoundException;
import java.rmi.NotBoundException;

/**
 * @author 大忽悠
 * @create 2022/7/8 9:35
 */
public class ElementBinderConfig {
    /**
     * 默认元素绑定的yml文件路径
     */
    public static final String DEFAULT_ELEMENT_YML="appiumElement.yml";

    private final YamlUtil yamlUtil;

    public ElementBinderConfig(String elementYml) {
        yamlUtil=new YamlUtil(elementYml);
    }

    public ElementBinderConfig() {
        yamlUtil=new YamlUtil(DEFAULT_ELEMENT_YML);
    }

    public String getElementLocateWay(String key){
        try {
            String res = yamlUtil.get(key);
            if(res==null){
                throw new NotBoundException("没有和当前key绑定的元素: "+key);
            }
            return res;
        } catch (FileNotFoundException | NotBoundException e) {
            throw new RuntimeException("传入定位元素查找方式key="+key+"有误");
        }
    }
}
